import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "Dashboard", icon: "al-dashboard", affix: true }
      }
    ]
  },
  {
    path: "/basic",
    component: Layout,
    redirect: "/basic/device",
    name: "basic",
    meta: { title: "基础库", icon: "al-model" },
    children: [
      {
        path: "device",
        name: "device",
        component: () => import("@/views/basic/index"),
        meta: { title: "设备管理", icon: "al-device" }
      },
      {
        path: "actionTherbligs",
        name: "actionTherbligs",
        component: () => import("@/views/basic/actionTherbligs"),
        meta: { title: "动素管理", icon: "al-operation" }
      },
      {
        path: "actionset",
        component: () => import("@/views/basic/MesActionSetList"),
        name: "actionset",
        meta: { title: "动作组管理", icon: "al-motion" }
      },
      {
        path: "worksection",
        component: () => import("@/views/basic/mesWorkSection"),
        name: "worksection",
        meta: { title: "工段管理", icon: "al-worksection" }
      }
    ]
  },
  {
    path: "/procedure",
    component: Layout,
    name: "procedure",
    meta: { title: "工序", icon: "al-procedure" },
    children: [
      {
        path: "procedureset",
        name: "procedureset",
        component: () => import("@/views/procedure/mesProcedureSet"),
        meta: { title: "工序管理", icon: "al-process" }
      },
      {
        path: "produceprocedure",
        name: "produceprocedure",
        component: () =>
          import("@/views/procedure/produce/mesProduceProcedure"),
        meta: { title: "生产工序线", icon: "al-processline" }
      },
      {
        path: "productprocedure",
        name: "productprocedure",
        component: () =>
          import("@/views/procedure/product/mesProductProcedure"),
        meta: { title: "产品工序线", icon: "al-productprocess" }
      },
      {
        path: "productproceduredispatch",
        name: "productproceduredispatch",
        component: () =>
          import("@/views/procedure/product/ModelProductProcedureDispatchList"),
        meta: { title: "产品工序线下发", icon: "al-dispatching" }
      },
      {
        path: "producewedf",
        name: "producewedf",
        component: () => import("@/views/procedure/produce/ProduceWEDFList"),
        meta: { title: "物料齐套", icon: "al-aligncenter" }
      }
    ]
  },
  {
    path: "/technology",
    component: Layout,
    name: "technology",
    meta: { title: "工艺库", icon: "al-technology" },
    children: [
      {
        path: "technologyset",
        name: "technologyset",
        component: () => import("@/views/technology/mesTechnologySet"),
        meta: { title: "标准工艺管理", icon: "al-standardtechnology" }
      }
    ]
  },
  {
    path: "/technologyFlow",
    component: Layout,
    name: "technologyFlow",
    meta: { title: "工艺流程管理", icon: "al-technologyflow" },
    children: [
      {
        path: "saletechnology",
        name: "saletechnology",
        component: () => import("@/views/technologyFlow/mesTechnologyFlow"),
        meta: { title: "销售工艺流程", icon: "al-technologytemplate" }
      }
    ]
  },
  {
    path: "/produceline",
    component: Layout,
    name: "produceline",
    meta: { title: "产线管理", icon: "al-productionManager" },
    children: [
      {
        path: "factoryproduceline",
        name: "producelinfactoryproducelineeset",
        component: () => import("@/views/produceLine/mesProduceLine"),
        meta: { title: "工厂产线", icon: "al-productionline" }
      }
    ]
  },

  {
    path: "/orderManager",
    component: Layout,
    name: "orderManager",
    meta: { title: "排产管理", icon: "al-schedule" },
    redirect: "/orderManager/order",
    children: [
      {
        path: "order",
        component: () => import("@/views/sale/SaleOrderMstList"),
        name: "order",
        meta: { title: "销售订单", icon: "al-order" }
      },
      {
        path: "dayreport",
        component: () => import("@/views/produce/ProduceDayReportList"),
        name: "dayreport",
        meta: { title: "日报工", icon: "al-dailyreport" }
      },
      {
        path: "stockmaterialex",
        component: () => import("@/views/wms/WMSStockExList"),
        name: "stockmaterialex",
        meta: { title: "扩展物料查询", icon: "al-materialquery" }
      },
      {
        path: "stockmaterial",
        component: () => import("@/views/wms/WMSStockList"),
        name: "stockmaterial",
        meta: { title: "物料查询", icon: "al-materialquery" }
      },
      {
        path: "produceCalendar",
        component: () => import("@/views/produce/ProduceCalendarList"),
        name: "produceCalendar",
        meta: { title: "工作日历", icon: "al-calendar" }
      },
      {
        path: "technologyQuery",
        component: () =>
          import("@/views/produce/technologyQuery/mesProductProcedure"),
        name: "technologyQuery",
        meta: { title: "工艺数据查询", icon: "al-technologyquery" }
      },
      {
        path: "scheduleMonth",
        component: () => import("@/views/produce/schedulePlan/index"),
        name: "scheduleMonth",
        meta: { title: "月计划", icon: "al-plan" },
        //redirect: '/orderManager/scheduleMonth/scheduleMonthPortal',
        children: [
          {
            path: "scheduleMonthPortal",
            component: () =>
              import("@/views/produce/schedulePlan/month/scheduleMonth"),
            name: "scheduleMonthPortal",
            meta: { title: "月计划主页", icon: "al-scheduleportal" }
          },
          {
            path: "scheduleMonthPlanDetail",
            component: () =>
              import(
                "@/views/produce/schedulePlan/month/scheduleMonthPlanDetail"
              ),
            name: "scheduleMonthPlanDetail",
            meta: { title: "月计划排产", icon: "al-scheduleplan" }
          },
          {
            path: "monthGantt",
            component: () =>
              import("@/views/produce/schedulePlan/month/monthGantt"),
            name: "monthGantt",
            meta: { title: "甘特图", icon: "al-gantt" }
          },
          {
            path: "materialRequiredList",
            component: () => import("@/views/supply/materialRequiredList"),
            name: "materialRequiredList",
            meta: { title: "物料需求表", icon: "al-productrequired" }
          }
        ]
      },
      {
        path: "produceStatics",
        component: () => import("@/views/produce/schedulePlan/statics/index"),
        //redirect:'/produceStatics/completestatic',
        name: "produceStatics",
        meta: { title: "生产统计", icon: "al-statics" },
        children:[{
          path: "completestatic/1",
          component: () =>
            import("@/views/produce/schedulePlan/statics/produceStatics"),
          name: "completestatic",
          meta: { title: "计划达成率", icon: "al-achievement" },
        },
        {
          path: "processstatic/2",
          component: () =>
            import("@/views/produce/schedulePlan/statics/produceStatics"),
          name: "processstatic",
          meta: { title: "进度统计", icon: "al-progress" },
        },
      ]
      }
    ]
  }
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;

export const asyncRouterMap = [
  {
    path: "/ums",
    component: Layout,
    redirect: "/ums/admin",
    name: "ums",
    meta: { title: "权限", icon: "ums" },
    children: [
      {
        path: "admin",
        name: "admin",
        component: () => import("@/views/ums/admin/index"),
        meta: { title: "用户列表", icon: "ums-admin" }
      },
      {
        path: "role",
        name: "role",
        component: () => import("@/views/ums/role/index"),
        meta: { title: "角色列表", icon: "ums-role" }
      },
      {
        path: "allocMenu",
        name: "allocMenu",
        component: () => import("@/views/ums/role/allocMenu"),
        meta: { title: "分配菜单" },
        hidden: true
      },
      {
        path: "allocResource",
        name: "allocResource",
        component: () => import("@/views/ums/role/allocResource"),
        meta: { title: "分配资源" },
        hidden: true
      },
      {
        path: "menu",
        name: "menu",
        component: () => import("@/views/ums/menu/index"),
        meta: { title: "菜单列表", icon: "ums-menu" }
      },
      {
        path: "addMenu",
        name: "addMenu",
        component: () => import("@/views/ums/menu/add"),
        meta: { title: "添加菜单" },
        hidden: true
      },
      {
        path: "updateMenu",
        name: "updateMenu",
        component: () => import("@/views/ums/menu/update"),
        meta: { title: "修改菜单" },
        hidden: true
      },
      {
        path: "resource",
        name: "resource",
        component: () => import("@/views/ums/resource/index"),
        meta: { title: "资源列表", icon: "ums-resource" }
      },
      {
        path: "resourceCategory",
        name: "resourceCategory",
        component: () => import("@/views/ums/resource/categoryList"),
        meta: { title: "资源分类" },
        hidden: true
      }
    ]
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true
  },
  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true }
];
